package com.viphome.security;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by wangzhanjin on 2017/12/22.
 */
@Aspect
@Component
public class SecurityAspect {

    @Autowired//校验的服务
    AuthService authService;

    //表达式，表达想往哪里切
    //它要拦截表示有AdminOnly的方法
    @Pointcut("@annotation(AdminOnly)")
    public void adminOnly(){

    }

    //advisor有很多种，执行之前插入一段代码
    @Before("adminOnly()")
    public void check(){
        authService.checkAccess();
    }

    @After("adminOnly()")
    public void logPrint(){
        System.out.println("打印了日志，delete方法执行完了。。。。。。。。。。。。。。");
    }
}
